
cat << EOF > $K8_CONFIG_HOME/kubelet.config

kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: $K8_HOST 
port: 10250
readOnlyPort: 10255
cgroupDriver: systemd
clusterDNS: ["$K8_CLUSTER_DNS"]
clusterDomain: cluster.local.
failSwapOn: false
authentication:
  anonymous:
      enabled: true

EOF


cat << EOF > $K8_CONFIG_HOME/kubelet

KUBELET_OPTS="--logtostderr=true \
    --v=4 \
    --hostname-override=$K8_HOST \
    --kubeconfig=$K8_CONFIG_HOME/kubelet.kubeconfig \
    --bootstrap-kubeconfig=$K8_CONFIG_HOME/bootstrap.kubeconfig \
    --config=$K8_CONFIG_HOME/kubelet.config \
    --cert-dir=$K8_CERT_HOME \
    --tls-cert-file=$K8_CERT_HOME/kube-server.pem \
    --tls-private-key-file=$K8_CERT_HOME/kube-server-key.pem \
    --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"


EOF

currentPath=$(pwd)

cat << EOF > $currentPath/build/service/kubelet.service

[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service
 
[Service]
EnvironmentFile=$K8_CONFIG_HOME/kubelet
ExecStart=$K8_NODE_BIN/kubelet \$KUBELET_OPTS
Restart=on-failure
KillMode=process
 
[Install]
WantedBy=multi-user.target

EOF



sed -i '/kubelet/d' $K8_NODE_SHELL
sed -i "/daemon-reload/i\cp $currentPath/build/service/kubelet.service $K8_SERVICE_HOME" $K8_NODE_SHELL

echo "$K8_CLIENT_BIN/kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap " >> $K8_NODE_SHELL
echo "systemctl enable kubelet" >> $K8_NODE_SHELL
echo "systemctl stop kubelet" >> $K8_NODE_SHELL
echo "systemctl start kubelet" >> $K8_NODE_SHELL




